<?php

require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php';
require_once 'standard/re/CodeFile.php';
re_CodeFile::load('re');

function _restrictOp_($tuple){
	return $tuple->S_NO == 'S1' || $tuple->S_NO == 'S2';
}

function _restrictOp1_($tuple, $filter){
	return in_array($tuple->S_NO, $filter);
}

function _restrictOp2_($tuple){
	return TRUE;
}

function _restrictOp3_($tuple){
	return FALSE;
}

function _tjoinOp_($tuple){
	return $tuple->STATUS > $tuple->STATUST;
}

function _tjoinOp2_($tuple){
	return $tuple->SCITY > $tuple->PCITY;
}


function _relExtend1_($tuple){
	return $tuple->a . $tuple->b . $tuple->e->theDecimal() . 'x';
}

function _relExtendExp1_($tuple){
	return $tuple->b * 5;
}

function _relExtendExp2_($tuple){
	return $tuple->d->plus(re::select('re_Test_Integer', 4, 'decimal'));	
}

function convertToGrams($tuple){
	return $tuple->WEIGHT * 454;
}

function convertToGrams_With_Units($tuple, $unit){
	return convertToGrams($tuple) . " " . $unit;
}

function _relationSubstitute_($t){
	return $t->c + $t->b + 10;
}
/*
function _extendExp3($tuple){
	return $tuple->STATUS + 5;
}

function _extendExp4($tuple){
	return 1;
}
*/
function _sampleRelationReadOnlyOperator($relation){

	$relation->assign(re::relation(array(
		array('a'=>1, 'b'=>5)
	)));
	
	if( re::isEqual(
			re::relation(array(
				array('a'=>1, 'b'=>5)
			))
		  ,$relation
		) == FALSE
	){
		throw new Exception("Must Be Equal.");
	};
}

class re_CommonOp
{

	static public function _restrictOp_($tuple){
		return $tuple->S_NO == 'S1' || $tuple->S_NO == 'S2';
	}

	public function _restrictOp1_($tuple, $filter){
		return in_array($tuple->S_NO, $filter);
	}
	
	
	public function _relExtendExp1_($tuple){
		return $tuple->b * 5;
	}

	public function _relExtendExp2_($tuple){
		return $tuple->d->plus(re::select('re_Test_Integer', 4, 'decimal'));	
	}

	public function _relExtendExp3_($tuple){
		return $tuple->STATUS + 5;
	}

	public function _relExtendExp4_($tuple){
		return 1;
	}

	static public function inst(){
		return new self;
	}
}